﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "UMG/GameStartWidget.h"

#include "Character/PlayerCharacter.h"
#include "Components/Button.h"
#include "Kismet/GameplayStatics.h"


// Sets default values
bool UGameStartWidget::Initialize()
{
	if (!Super::Initialize())
	{
		return false;
	}
	StartGameBtn->OnClicked.AddDynamic(this, &UGameStartWidget::StartGameBtnFunc);
	EndGameBtn->OnClicked.AddDynamic(this, &UGameStartWidget::EndGameBtnFunc);
	return true;
}

void UGameStartWidget::StartGameBtnFunc()
{
	// player恢复操作
	APlayerCharacter* PlayerPawn = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
	if (PlayerPawn)
	{
		PlayerPawn->StartOperation();
	}
	UGameplayStatics::OpenLevel(GetWorld(), FName("SunTemple"));
}

void UGameStartWidget::EndGameBtnFunc()
{
	UKismetSystemLibrary::QuitGame(GetWorld(), nullptr, EQuitPreference::Quit, true);
}
